package com.zhu.classfile.constant.factory;

import com.zhu.classfile.constant.ConstantInfo;
import com.zhu.classfile.constant.ConstantPool;
import com.zhu.classfile.constant.base.*;

public class ConstantInfoFactory {
//    public static ConstantInfo newConstantInfo(int tag, ConstantPool cp) {
//        return switch (tag) {
//            case 1 -> new ConstantUtf8Info();
//            case 3 -> new ConstantIntegerInfo();
//            case 4 -> new ConstantFloatInfo();
//            case 5 -> new ConstantLongInfo();
//            case 6 -> new ConstantDoubleInfo();
//            case 7 -> new ConstantClassInfo(cp);
//            case 8 -> new ConstantStringInfo(cp);
//            case 9 -> new ConstantFieldrefInfo(cp);
//            case 10 -> new ConstantMethodrefInfo(cp);
//            case 11 -> new ConstantInterfaceMethodrefInfo(cp);
//            case 12 -> new ConstantNameAndTypeInfo(cp);
////            case 15 -> new ConstantMethodHandleInfo(cp);
////            case 16 -> new ConstantMethodTypeInfo(cp);
////            case 18 -> new ConstantInvokeDynamicInfo(cp);
//            default -> throw new RuntimeException("Unsupported constant tag: " + tag);
//        };
//    }

    public static ConstantInfo newConstantInfo(int tag, ConstantPool cp) {
        ConstantInfo info;
        switch (tag) {
            case 1:
                info = new ConstantUtf8Info();
                break;
            case 3:
                info = new ConstantIntegerInfo();
                break;
            case 4:
                info = new ConstantFloatInfo();
                break;
            case 5:
                info = new ConstantLongInfo();
                break;
            case 6:
                info = new ConstantDoubleInfo();
                break;
            case 7:
                info = new ConstantClassInfo(cp);
                break;
            case 8:
                info = new ConstantStringInfo(cp);
                break;
            case 9:
                info = new ConstantFieldrefInfo(cp);
                break;
            case 10:
                info = new ConstantMethodrefInfo(cp);
                break;
            case 11:
                info = new ConstantInterfaceMethodrefInfo(cp);
                break;
            case 12:
                info = new ConstantNameAndTypeInfo(cp);
                break;
//        case 15:
//            info = new ConstantMethodHandleInfo(cp);
//            break;
//        case 16:
//            info = new ConstantMethodTypeInfo(cp);
//            break;
//        case 18:
//            info = new ConstantInvokeDynamicInfo(cp);
//            break;
            default:
                throw new RuntimeException("Unsupported constant tag: " + tag);
        }
        return info;
    }
}
